package com.yy.wga.mp.module.user.controller;


import com.yy.wga.common.core.dto.Result;
import com.yy.wga.common.utils.mapping.BeansUtils;
import com.yy.wga.mp.common.interceptor.RequestUserHolder;
import com.yy.wga.mp.module.user.request.UserRelationListRequest;
import com.yy.wga.mp.module.user.response.UserRelationListResponse;
import com.yy.wga.user.feign.api.UserRelationFeign;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 用户粉丝关系
 *
 * @author guochao
 * @since 2024-12-10 22:41:43
 */
@RestController
@RequestMapping(value = "/api/user/relation/")
public class UserRelationController {
    /**
     * 服务对象
     */
    @Resource
    private UserRelationFeign userRelationService;

    /**
     * 查询粉丝列表
     * @return
     */
    @PostMapping("list")
    public Result<List<UserRelationListResponse>> list(@RequestBody @Valid UserRelationListRequest request) {
        com.yy.wga.user.feign.request.UserRelationListRequest userRelationListRequest = BeansUtils.map(request, com.yy.wga.user.feign.request.UserRelationListRequest.class);
        userRelationListRequest.setParentUserId(RequestUserHolder.getUserCache().getUserId());
        Result<List<com.yy.wga.user.feign.response.UserRelationListResponse>> result = userRelationService.list(userRelationListRequest);
        if (result.isSuccess()) {
            List<com.yy.wga.user.feign.response.UserRelationListResponse> data = result.getData();
            List<UserRelationListResponse> userRelationListResponseList = BeansUtils.mapList(data, UserRelationListResponse.class);
            return Result.success(userRelationListResponseList);
        }
        return Result.fail(result.getMessage());
    }

}
